<template>
  <div class="base-container" id="main">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="() => { this.pagination.current = 1; this.getList() }"
            @reset="() => { this.pagination.current = 1; this.getList() }">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="地方标准章条编号" name="projectName">
            <t-input v-model="queryParams.chapterNum" clearable placeholder="请输入地方标准章条编号" style="width: 240px" />
          </t-form-item>
          <t-form-item label="提出人" name="personName">
            <t-input v-model="queryParams.personName" clearable placeholder="请输入提出人姓名" style="width: 240px" />
          </t-form-item>
          <t-form-item label="提出单位" name="deptName">
            <t-input v-model="queryParams.deptName" clearable placeholder="请输入单位名称" style="width: 240px" />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-table
      rowKey="index"
      :data="data"
      :columns="columns"
      >
      <template  #op="{ row }">
        <t-button size="small" variant="text" class="t-button-link" v-if="row.summary==='0'" @click="summary(row)"> <t-icon name="edit-1" slot="icon"/>汇总</t-button>
        <t-button size="small" variant="text" class="t-button-link" v-else disabled @click="summary(row)"> <t-icon name="edit-1" slot="icon"/>汇总</t-button>
      </template>
      <template  #dealOpinion="{ row }">
        <t-tag :theme="handleTheme(row.dealOpinion,dict.type.deal_opinion)" variant="light" v-if="row.dealOpinion!==''&&row.dealOpinion!==null&&row.dealOpinion!==undefined">
          {{row.dealOpinion | filterByDict(dict.type.deal_opinion)}}
        </t-tag>
        <span v-else>
         -
        </span>
      </template>
      <template  #summary="{ row }">
        <t-tag v-if="row.summary==='1'" theme="success"  variant="light">已汇总</t-tag>
        <t-tag v-else theme="default"  variant="light">未汇总</t-tag>
      </template>
    </t-table>
    <t-dialog top="5%" width="60%" :visible.sync="summaryForm" header="汇总意见" :onConfirm="onSubmit">
      <div style="height: 65vh">
        <t-form :data="formData" ref="form" :colon="true"  @submit="onSubmit" :rules="rules">
          <t-form-item name="dealOpinion" label="处理意见">
            <t-select clearable v-model="formData.dealOpinion" :options="dict.type.deal_opinion">
            </t-select>
          </t-form-item>
          <t-form-item name="note" label="备注">
            <t-textarea v-model="formData.note" :autosize="{ minRows: 3 }" placeholder="请输入您的备注" />
          </t-form-item>
          <!--        <t-form-item label="是否汇总" name="summary">-->
          <!--          <t-radio-group v-model="formData.summary">-->
          <!--            <t-radio value="0">否</t-radio>-->
          <!--            <t-radio value="1">是</t-radio>-->
          <!--          </t-radio-group>-->
          <!--        </t-form-item>-->
        </t-form>
      </div>
    </t-dialog>
  </div>

</template>

<script>
export default {
  name: "opinion-summary",
  dicts:["deal_opinion"],
  data(){
    return{
      nowRow:{},
      rules: {
        dealOpinion: [
          {
            required: true,
            message: "处理意见不能为空",
          },
        ],
        // note: [
        //   {
        //     required: true,
        //     message: "备注不能为空",
        //   },
        // ],
        // summary: [
        //   {
        //     required: true,
        //     message: "汇总不能为空",
        //   },
        // ],

      },
      formData:{
        dealOpinion:"",
        note:"",
        summary:"1"
      },
      summaryForm:false,
      sort: [],
      queryParams: {
        pageNum: 1,
        pageSize:10,
        chapterNum: "",
        personName:"",
        deptName:"",
        formulateType: "",
      },
      pagination: {
        dafaultCurrent: 1,
        defaultPageSize: 10,
        total: 0,
        showPageSize: false,
        showFirstAndLastPageBtn: false,
        current: 1,
        onchange(pageInfo) {
          this.pagination.current = pageInfo.current
          this.getList()
        }
      },
      data:[],
      columns: [
        {
          colKey: 'chapterNum',
          title: '地方标准章条编号',
          align:"center"

        },
        {
          colKey: 'opinion',
          title: '意见内容',
          align:"center"
        },
        {
          colKey: 'personName',
          title: '提出人',
          align:"center"
        },
        {
          colKey: 'deptName',
          title: '提出单位',
          align:"center"
        },
        {
          colKey: 'summary',
          title: '汇总状态',
          align:"center"
        },
        {
          colKey: 'dealOpinion',
          title: '处理意见',
          align:"center"
        },
        {
          colKey: 'op',
          title: '操作',
          align:"center"
        },
      ],
      id:""
    }
  },
  async mounted() {
    // if(!this.$route.query.id){
    //   await this.$message.error("未找到汇总id")
    //   this.$router.push('/bzh/opinion/opinion-my')
    // }
    this.id = this.$route.query.id
    await this.getList()
  },
  methods:{
    async onSubmit() {
      this.$refs.form.validate().then(async (validateResult) => {
        if (validateResult === true) {
          this.formData.id = this.nowRow.id
          this.$api.bzh.opinion.update(this.formData).then(res=>{
            this.getList()
            this.summaryForm = false
            this.$message.success("提交成功")
          }).catch(err=>{
            this.$message.error(err)
          })
        } else {
          const firstError = Object.values(validateResult)[0]?.[0]?.message;
          this.$message.error(firstError)
        }
      })


    },
    getList(){
      //  return this.$api.bzh.opinion.localStandardList({localId:this.id}).then(res=>{ return this.$api.bzh.opinion.localStandardList({localId:this.id}).then(res=>{
      this.queryParams.localId = this.id
      return this.$api.bzh.opinion.localStandardList(this.queryParams).then(res=>{
        this.data = res.rows
      }).catch(err=>{
        this.$message.error(err)
      })
    },
    summary(row){
      this.nowRow = row
      this.summaryForm = true
    },
  }
}
</script>

<style scoped>

</style>
